
package com.hc.dao.impl;

import org.springframework.stereotype.Repository;

import com.hc.dao.IUserAndRoleDao;
import com.hc.domain.Role;
import com.hc.domain.UserAndRole;
@Repository
public class UserAndRoleDaoImpl extends BaseDaoImpl<UserAndRole> implements IUserAndRoleDao {

	@Override
	public int getRoleUserCount(int roleId) {
		Long count = super.count("SELECT count(u.adminId) FROM UserAndRole u WHERE u.roleId = ?", new Object[]{roleId});
		if (count!=null){
			return count.intValue();
		}
		return 0;
	}

	@Override
	public void deleteUserAuthByRole(Role role) throws Exception {
		super.executeHql("DELETE FROM UserAndRole u WHERE u.roleId=?", new Object[]{role.getId()});
	}

	@Override
	public UserAndRole getUserRoleByUserId(Integer id) {
		return super.get("FROM UserAndRole u WHERE u.adminId=?", new Object[]{id});
		
	}

	@Override
	public void updateOrSave(UserAndRole uar) {
		super.saveOrUpdate(uar);
	}

}

